#ifndef __CCMS_NR_NODE_STATS_H__
#define __CCMS_NR_NODE_STATS_H__

/**
 * @file ccms/nr/node_stats.h
 *
 * NodeStats class header file.
 */

#include "ccms/nr/types.h"
#include "ccms/nr/cpu_stats.h"
#include "ccms/nr/mem_stats.h"
#include "ccms/nr/processes_tab.h"
#include <list>
#include <unistd.h>

namespace ccms {
namespace nr {

/**
 * NodeStats class, is a top-level interface to the Node Resources
 * information and statistics.
 */
class NodeStats
{
    public:

        /**
         * Default constructor.
         */
        NodeStats(void);

        /**
         * Updates the internal data about currently running processes
         * as well as about system-wide cpu & memory usage.
         */
        void update(void);

        /**
         * Returns the percentage of the total CPU usage 
         * of a particular mode
         * 
         * @param mode - cpu usage mode
         * @throw InvalidParameterException if an invalid mode is passed
         * @return percentage of the total CPU usage of
         *         the particular mode
         */
        unsigned int getTotalCpuUsage(const CpuUsageMode mode) const;
        
        /**
         * Returns the percentage of the CPU usage of a process
         * identified by pid, of cpu usage mode.
         *
         * @param pid - Process ID (PID) of the process
         * @param mode - cpu usage mode
         * @throw InvalidParameterException if an invalid \a mode is passed
         *        or the process identified by \a pid is currently
         *        not monitored
         * @return percentage of the CPU usage of the process
         *         identified by pid, of cpu usage mode
         */
        unsigned int getProcessCpuUsage(const pid_t pid, const CpuUsageMode mode) const;

        /**
         * Returns the total memory usage of a particular mode, in kB.
         *
         * @param mode - mem usage mode
         * @throw InvalidParameterException if an invalid mode is passed
         * @return total memory usage of a particular mode
         */
        unsigned long getTotalMemUsage(const MemUsageMode mode) const;

        /**
         * Returns the amount of memory used by a process identified by uid,
         * in kB.
         *
         * @param pid - Process ID (PID)
         * @param mode - mem usage mode (currently only MEM_USAGE_MODE_PHYS_USED
         *               is supported)
         * @throw InvalidParameterException if an invalid \a mode is passed
         *        or the process identified by \a pid is currently
         *        not monitored
         * @return the amount of memory allocated by user's processes
         */
        unsigned long getProcessMemUsage(const pid_t pid,
            const MemUsageMode mode = MEM_USAGE_MODE_PHYS_USED) const;

        /**
         * Registers a new process to be watched.
         * @param pid - pid of the process to be watched
         */
        void registerWatchedProcess(const pid_t pid);

        /**
         * Unregisters a process that is watched.
         * @param pid - pid of the process not to be watched anymore
         */
        void unregisterWatchedProcess(const pid_t pid);

    private:

        /**
         * ProcessesTab for information about processes in the system.
         */
        ProcessesTab processesTab;

        /**
         * CpuStats for system-wide info about cpu usage.
         */
        CpuStats cpuStats;

        /**
         * MemStats for system-wide info about mem usage.
         */
        MemStats memStats;
};

} // namespace nr
} // namespace ccms

#endif /* __CCMS_NR_NODE_STATS_H__ */
